package thirt.component
{
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.GlowFilter;
	
	import mx.controls.Button;

	public class DRadio extends Button
	{
		private var _select:Boolean;
		private var filt:GlowFilter;
		private var fade:Boolean;
		public var fadeFilt:GlowFilter;
		public function DRadio()
		{
			super();
			filt = new GlowFilter(0x1c9cf6,1,8,8);
			fadeFilt = new GlowFilter(0x7BB2CC,1,20,20,2);
			this.addEventListener(MouseEvent.ROLL_OVER,onOver);
			this.addEventListener(MouseEvent.ROLL_OUT,onOut);
			//this.filters = [filt];
		}
		public function set select(value:Boolean):void{
			this._select = value;
			if(value){
				this.removeEventListener(MouseEvent.ROLL_OVER,onOver);
				this.removeEventListener(MouseEvent.ROLL_OUT,onOut);
				this.removeEventListener(Event.ENTER_FRAME,onFrame);
				this.filters = [filt];
			}else{
				this.filters = null;
				this.addEventListener(MouseEvent.ROLL_OVER,onOver);
				this.addEventListener(MouseEvent.ROLL_OUT,onOut);
			}
		}
		public function get select():Boolean{
			return this._select;
		}
		
		private function onOver(event:Event):void{
			if(this._select){
				return;
			}
			fade = true;
			this.addEventListener(Event.ENTER_FRAME,onFrame);
		}
		private function onOut(event:Event):void{
			if(this._select){
				return;
			}
			fade = false;
			this.addEventListener(Event.ENTER_FRAME,onFrame);
		}
		private function onFrame(event:Event):void{
			if(fade){
				if(fadeFilt.alpha <= 1){
					fadeFilt.alpha += 0.2;
				}else{
					this.removeEventListener(Event.ENTER_FRAME,onFrame);
				}
			}else{
				if(fadeFilt.alpha >= 0){
					fadeFilt.alpha -= 0.2;
				}else{
					this.removeEventListener(Event.ENTER_FRAME,onFrame);
				}
			}
			this.filters = [fadeFilt];
		}
		public function clone():DRadio{
			var dr:DRadio = new DRadio;
			dr.styleName = "sizeBtn";
			dr.width = 41;
			dr.height = 27;
			dr.label = this.label;
			dr.setStyle("fontWeight","normal");
			dr.setStyle("paddingTop","-1");
			dr.setStyle("fontSize","14");
			dr.setStyle("color","#666666");
			dr.data = this.data;
			return dr;
		}
		
	}
}